package com.cy.pj.sys.service.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class SysTimeAspect {
    @Pointcut("bean(sysUserServiceImpl)")
    public void doTime(){}
    @Before("doTime()")
    public void doBefore(){//在业务方法执行前执行
        System.out.println("@Before");
    }
    @After("doTime()")
    public void doAfter(){//在业务方法结束时执行
        System.out.println("@After");
    }
    @AfterReturning("doTime()")
    public void doAfterReturning(){//在业务方法正常结束执行
        System.out.println("@AfterReturning");
    }
    @AfterThrowing("doTime()")
    public void doAfterThrowing(){//在业务方法异常结束执行
        System.out.println("@AfterThrowing");
    }

    @Around("doTime()")
    public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
        System.out.println("@Around.before");
        try {
            Object result=proceedingJoinPoint.proceed();
            System.out.println("@Around.afterReturning");
            return result;
        }catch (Throwable e){
            e.printStackTrace();
            System.out.println("@Around.afterThrowing");
            throw e;
        }finally {
            System.out.println("@Around.after");
        }
    }
}
